package com.rk.live.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.rk.live.R;

public class BehindListAdapter extends BaseAdapter {

	private ViewHolder holder;
	private Context mContext;
	private List<String> list = null;
	private int currentItem = 0;

	public BehindListAdapter(Context mContext) {
		this.mContext = mContext;
		initData();
	}

	private void initData() {
		list = new ArrayList<String>();
		list.add(mContext.getResources().getString(R.string.menuGood));
		list.add(mContext.getResources().getString(R.string.menuNews));
		list.add(mContext.getResources().getString(R.string.menuStudio));
		list.add(mContext.getResources().getString(R.string.menuBlog));
	}
	
	public void setCurrentItem(int position){
		this.currentItem = position;
	}

	@Override
	public int getCount() {
		if (list == null) {
			return 0;
		}
		return list.size();
	}

	@Override
	public String getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		convertView = this.getViewHolder(convertView);
		if (position == currentItem) {
			convertView.setBackgroundResource(R.drawable.back_behind_list);
		} else {
			convertView.setBackgroundColor(Color.TRANSPARENT);
		}
		// sourceInfo = loadList.get(position);
		holder.title.setText(list.get(position));
		holder.img.setBackgroundResource(R.drawable.dis_menu_studio);
		return convertView;
	}

	/**
	 * 获取viewholder
	 * 
	 * @param convertView
	 */
	private View getViewHolder(View convertView) {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.behind_list_show, null);
			holder = new ViewHolder();
			holder.img = (ImageView) convertView
					.findViewById(R.id.imageview_behind_icon);
			holder.title = (TextView) convertView
					.findViewById(R.id.textview_behind_title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

	static class ViewHolder {
		ImageView img;
		TextView title;
	}

}
